package com.bilicute.libman.mapper;

import com.bilicute.libman.pojo.Book;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BookMapper {
    @Select("select * from book where book_id = #{id}")
    Book findBookById(Integer id);

    @Update("UPDATE book " +
            "SET book_status = 1, " +
            "book_borrower = #{loggedInUserId}, " +
            "book_borrowtime = now(), " +
            "book_returntime = NULL, " +
            "record_id_in_book = #{recordId} "+
            "WHERE book_id = #{id}")
    void borrow(Integer id, Integer loggedInUserId,String recordId);

    @Update("UPDATE book " +
            "SET book_status = 2, " +
            "book_returntime = now() " +
            "WHERE book_id = #{id}")
    void resultBook(Integer id);

    @Insert("insert into book( book_name , book_isbn , book_press , book_author, book_pagination , book_price, book_uploadtime, book_status ) " +
            "value(#{book_name}, #{book_isbn}, #{book_press}, #{book_author}, #{book_pagination}, #{book_price}, now(), 0)")
    void add(Book book);

    @Update("UPDATE book SET book_status = 3 WHERE book_id = #{id}")
    void off(Integer id);

    @Update("UPDATE book SET book_status = 0 ,record_id_in_book = NULL WHERE book_id = #{id}")
    void pass(Integer id);

    List<Book> list(Integer book_status);

    @Select("SELECT COUNT(*) FROM book")
    Integer getAllNum();

    List<Book> listMyBorrow(Integer book_status, Integer loggedInUserId);

    @Delete("delete from book where book_id=#{id}")
    void delete(Integer id);
}
